/**
 * Created by Chris on 14/11/21.
 */
require(['zepto'], function(){
//    alert("mobile_main ready!");
    $(".js-nav-menu-toggle").bind('click', function(){
//       alert("click");
        var $target = $($(this).data('target'));
        var menuStatus = $target.attr('status');
        console.log("menuStatus["+menuStatus+"]");
        if (menuStatus=='on'){
            $target.attr('status', 'off');
            $target.hide();
        }else{
            $target.attr('status', 'on');
            $target.show();
        }
    });


    $(".js-dq-close-share-tips").bind('click', function(){
        var target = $(this).data('target');
        setCookie("share_tips", 'no', 0);
        $(target).hide();
    });

    $(".js-dq-remove-share-tips").bind('click', function(){
        var target = $(this).data('target');
        setCookie("share_tips", 'no', 0);
//        $(target).hide();
        // redirect to the specify share page
        self.location = "/mobile/user/list/doShare"

        // show the share box
        /*
        var $shareBox =$("#shareBox");
        if ($shareBox&&$shareBox.length>0){
            $shareBox.show();
        }
        */
    });

    $(".js-showEl").bind('click',function(){
       var target = $($(this).data('target'));
        console.log("js-showEl click target["+target+"]");
        if (target && target.length>0){
            target.show();
        }
    });

    $(".js-redirect-url").bind('click',function(){
       var target =$(this).data('target');
        self.location= target;
    });
    $(".js-fn-call").bind('click',function(){
       var target = $(this).data('target');
        eval(target+'()');
    });
    $(".js-form-submit").bind('click',function(){
       var target = $(this).parent('form');
        target.submit();

    });


    var share_tips = getCookie("share_tips");
    if (share_tips=="yes"){
        // show the share tips
        var $shareTips = $('.share-tips');
        if ($shareTips&&$shareTips.length>0){
            $('.share-tips').show();
        }
    }
});



function setCookie(name, value, expireday) {
    var exp = new Date();
    exp.setTime(exp.getTime() + expireday*24*60*60*1000); //设置cookie的期限
    document.cookie = name+"="+escape(value)+"; expires"+"="+exp.toGMTString()+"; path=/";//创建cookie
}

function getCookie(name) {
    var cookieStr = document.cookie;
    if(cookieStr.length > 0) {
        var cookieArr = cookieStr.split(";"); //将cookie信息转换成数组
        for (var i=0; i<cookieArr.length; i++) {
            var cookieVal = cookieArr[i].split("="); //将每一组cookie(cookie名和值)也转换成数组
            if( cookieVal[0].replace(" ", "") == name) {
                return unescape(cookieVal[1]); //返回需要提取的cookie值
            }
        }
    }
}

